# 实战 线程池
from concurrent.futures import ThreadPoolExecutor

import requests


def downloadChapter(bookid, chapter_id):
    # TODO 先不做破解了
    print(f"下载章节:{bookid}--{chapter_id}")
    pass


def downloadBook(bookid):
    # 1. 下载一本书的章节列表
    url = f"https://boxnovel.baidu.com/boxnovel/wiseapi/chapterList?bookid={bookid}&pageNum=1&order=asc&site="
    resp = requests.get(url)
    json = resp.json()
    chapterInfoList = json["data"]["chapter"]["chapterInfo"]

    with ThreadPoolExecutor(10) as t:
        for chapter in chapterInfoList:
            chapter_id = chapter["chapter_id"]
            t.submit(downloadChapter, bookid, chapter_id)

    pass


if __name__ == '__main__':
    bookid = "4305469496"
    # chapter_id = "10346569"
    # downloadChapter(bookid, chapter_id)

    downloadBook(bookid)
    print("over!!")
